package com.yehuishou.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yehuishou.pojo.Partner;
import com.yehuishou.service.PartnerService;

@Controller
public class PartnerController {

	@Autowired
	private PartnerService partners;
	
	//查询所有
	@RequestMapping("content-7_1")
	public String partner(@RequestParam(required=true,defaultValue="1") Integer pageNum,
			@RequestParam(required=true,defaultValue="5") Integer pageSize,
			Model model) {
		PageHelper.startPage(pageNum, pageSize);
		List<Partner>list = partners.findAll();
		PageInfo<Partner> p=new PageInfo<Partner>(list);
		model.addAttribute("page", p);
	    model.addAttribute("list",list);
		return "content-7_1";
	}
	
	//跳转添加
	@RequestMapping("partneradd")
	private String add() {
		return"partneradd";
	}
	
	//添加
	@RequestMapping("partneradds")
	private String adds(Partner partner) {
		partners.add(partner);
		return"redirect:content-7_1";
	}
	
	//删除
	@ResponseBody
	@RequestMapping("partnerdele")
	private int dele(Integer id) {
		int i = partners.dele(id);
		if (i > 0) {
			return 1;
		}
		return 2;
	}
}
